package ihistoryApp.dal.controller;

import ihistoryApp.dal.entity.Message;
import ihistoryApp.request.GetChatListRequest;
import ihistoryApp.request.GetLastMessageRequest;
import ihistoryApp.service.MessageService;
import ihistoryApp.view.LastMessageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/chat")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @PostMapping("/getChatList")
    public ResponseEntity<List<Message>> getChatList(@RequestBody GetChatListRequest request) {
        return ResponseEntity.ok(messageService.getChatList(request));
    }

    @PostMapping("/getLastMessage")
    public ResponseEntity<List<LastMessageResponse>> getLastMessage(@RequestBody GetLastMessageRequest request) {
        return ResponseEntity.ok(messageService.getLastMessage(request));
    }


}
